  // pages/muisc/muisc.js
import ClassicModel from '../../models/classic.js'
import StartModel from '../../models/start'
const  classic = new ClassicModel()
const start = new StartModel()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    likeCount: 0,
    likeStatus: false,
    lastdata:null,
    latest: true,
    first: false,
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    classic.getLatest((res)=> {
      this.setData({
        lastdata:res,
        likeCount:res.fav_nums,
        likeStatus: res.like_status
      })
      // console.log(res)
    })
  },

  onLike:function(event) {
    // console.log(event)
    const behavior = event.detail.behavior
      start.like(behavior, this.data.lastdata.id,
        this.data.lastdata.type)

  },

  onNext:function(e) {
    this._updateClassic('next')
  },
  onPrevious:function(e) {
    this._updateClassic('previous')
  },
  _updateClassic(nextOrPrevious){
    const index = this.data.lastdata.index
    classic.getClassic(index,nextOrPrevious,(res) => {
      // console.log(res)
      this.setData({
        lastdata: res,
        latest: classic.isLatest(res.index),
        first: classic.isFirst(res.index)
      })
    })
  },
  _getLikeStatus(artID,category) {
    start.getClassicLikeStatus(artID,category,(res)=>{
      this.setData({
        likeCount: res.fav_nums,
        likeStatus: res.like_status
      })
    })
  }

  /**
   * 生命周期函数--监听页面初次渲染完成
   */

})